package com.android.camera.one.config;

import com.android.camera.debug.Log;
import com.android.camera.one.OneCameraCharacteristics;
import com.android.camera.one.config.OneCameraFeatureConfig.CaptureSupportLevel;
import com.google.common.base.Optional;

import android.hardware.camera2.CameraMetadata;

public class OneCameraAvailableCapabilities {
	private static final Log.Tag TAG = new Log.Tag("OneCamAvailCaps");
	
	public static enum RequestCapabilities {
		BACKWARD_COMPATIBLE,
		MANUAL_SENSOR,
		MANUAL_POST_PROCESSING,
		RAW,
		PRIVATE_REPROCESSING,
		READ_SENSOR_SETTINGS,
		BURST_CAPTURE,
		YUV_REPROCESSING,
		DEPTH_OUTPUT,
		CONSTRAINED_HIGH_SPEED_VIDEO;
		
		public static int toMetadata(RequestCapabilities flag) {
			switch (flag) {
			case BACKWARD_COMPATIBLE:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE;
			case MANUAL_SENSOR:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR;
			case MANUAL_POST_PROCESSING:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING;
			case RAW:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_RAW;
			case PRIVATE_REPROCESSING:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING;
			case READ_SENSOR_SETTINGS:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS;
			case BURST_CAPTURE:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE;
			case YUV_REPROCESSING:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING;
			case DEPTH_OUTPUT:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT;
			case CONSTRAINED_HIGH_SPEED_VIDEO:
				return CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO;
			}
			return -1;
		}
	}
	
	private final int[] mCapabilities;
	
	public OneCameraAvailableCapabilities(OneCameraCharacteristics cameraCharacteristics) {
		mCapabilities = cameraCharacteristics.getRequestAvailableCapabilities();
		for (int c: mCapabilities) {
			Log.d(TAG, "getRequestAvailableCapabilities "+c);
		}
	}
	
	public boolean isSupport(RequestCapabilities capability) {
		int cap = RequestCapabilities.toMetadata(capability);
        for (int c: mCapabilities) {
            if (c == cap) return true;
        }
        return false;
	}
}
